<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第2章习题</title>
</head>
<body>
    1.计算圆的周长和面积
    <div>
        <p>圆的半径：<input id="r" type="text"></p>
        <p>圆的周长：<input id="cir" type="text"></p>
        <p>圆的面积：<input id="area" type="text"></p>
    </div>
    2.四则运算
    <div>
    <P>请输入第一个数：<input id="num1" type="number"></P>
    <P>请输入第二个数：<input id="num2" type="number"></P>
    <button id="jia">加</button>
    <button id="jian">减</button>
    <button id="cheng">乘</button>
    <button id="chu">除</button>
    <P>运算结果：<input id="result" type="number"></P>
</div>
3.流程控制-选择
<div>
    <p>请输入你的成绩：<input id="score" type="number"></p>
    <button id="check">查询</button>
    <p>你的等级是：<input id="rank" type="text"></p>
</div>
4.流程控制-循环1）求100内偶数的和2)打印金字塔<br>
5.打印九九表<br>
6.1-100的素数<br>
7.红白25个，白黑31个，红黑28个，求这三个球各多少个<br>
</body>
<script>
    var r=prompt('请输入圆的半径');
    r=parseFloat(r)&& Number(r);
    if (!isNaN(r)){
        var cir=2*Math.PI.toFixed(2)*r;
        var area=Math.PI.toFixed(2)*r*r;
        document.getElementById('r').value=r;
        document.getElementById('cir').value=cir.toFixed(2);
        document.getElementById('area').value=area.toFixed(2);
    }else{
        alert('请输入正确的数字')
    }
</script>
<script>
      var x=document.getElementById("num1");
      var y=document.getElementById("num2");

  document.getElementById("jia").onclick=function(){
        document.getElementById("result").value=parseFloat(x.value)+parseFloat(y.value);
    },
    document.getElementById("jian").onclick=function(){
        document.getElementById("result").value=parseFloat(x.value)-parseFloat(y.value);
    },
    document.getElementById("cheng").onclick=function(){
        document.getElementById("result").value=parseFloat(x.value)*parseFloat(y.value);
    },
    document.getElementById("chu").onclick=function(){
        document.getElementById("result").value=parseFloat(x.value)/parseFloat(y.value);
    }


</script>
<script>
    document.getElementById("check").onclick=function(){
        var score=parseInt(document.getElementById('score').value);
        rank=document.getElementById('rank');
        score=score/10;
        switch(parseInt(score)){
            case 10:
            rank.value="优秀";
            break
            case 9:
            rank.value="良";
            break
            case 8:
            rank.value="中等";
            break
            case 7:
            rank.value="一般";
            break
            case 6:
            rank.value="及格";
            break;
            case 5:
            rank.value="不及格";
            break
            case 4:
            rank.value="不及格";
            break
            case 3:
            rank.value="不及格";
            break
            case 2:
            rank.value="不及格";
            break
            case 1:
            rank.value="不及格";
            break
        }
    }
</script>
<script>
    var sum_o = 0;
    for(var i=2;i<=100;i+=2){
        sum_o+=i;
    }
    document.write(sum_o);
</script><br>
<script>
    var  level=prompt('请设置金字塔的层数');
    level=parseFloat(level)&&Number(level);
    if(isNaN(level)){
        alert('金字塔的层数必须是纯数字');
    }
    for(var i=1;i<=level;++i){
        var blank=level-i;
        for(var k=0;k<blank;++k){
            document.write('&nbsp;');
        }
        var star=i*2-1;
        for(var j=0;j<star;++j){
            document.write('*');
        }
        document.write('<br>');
    }
</script>
<script>
    var a,b
    for(a=1;a<=9;a++){
      for(b=1;b<=a;b++)
          document.write("&nbsp;"+a,'*',b,'=',a*b,'')
      
      document.write('<br>')
    }
     </script>
     <script>
       
       for( var i=2; i<100; i++){
              var falg=true;
               for (var j=2; j<i; j++){
                   if ( i%j==0){
                       falg=false;
                   }
               }
               if(falg){
                   document.write('<br>',+i);
               }
           }
       </script>
       <script>
           for (var red=0; red<=25;red++){
               var white=25-red;black=28-red;
               if(31==white+black){
                   alert("red："+red+"\n"+"black:"+black+"\n"+"white:"+white)
               }
           }
       </script><br>

</html>